import { createSlice,createAsyncThunk } from "@reduxjs/toolkit"
import {getRequest} from '../../api/movie'

// 异步action 发送请求 获取列表信息
export const getMovieAction =createAsyncThunk('movie/getmovie',async()=>{
    const re = await getRequest()
    // console.log(re);
    return re.data.data.list
})

const movieSlice  = createSlice({
    name:"movie",
    initialState:{
        movieList:[]
    },
    
    reducers:{
        
    },
    extraReducers:{
        [getMovieAction.fulfilled](prev,action){
            console.log("异步action成功--getMovieAction");
        //    console.log(prev,action,'getmovieaction')
           prev.movieList = action.payload
        },
        [getMovieAction.rejected](prev,action){
            console.log("异步action失败--getMovieAction");
          
        },
        [getMovieAction.pending](prev,action){
            console.log("异步action正在进行--getMovieAction");
            // console.log(prev,action,'getmovieaction')
          
        }
    }
})
export default movieSlice.reducer